/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 同步阻塞消费者
 * @Description *
 * @Package concurrent.blockingQueue
 * @date 2021/3/19 1:50 下午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package concurrent.blockingQueue.bqtest;

import java.util.concurrent.BlockingQueue;

public class Consumer extends Thread {

  

    BlockingQueue<String> blockingDeque;

    public Consumer(BlockingQueue<String> blockingDeque) {
        this.blockingDeque = blockingDeque;
    }

    @Override
    public void run() {
        try {
            for (; ; ) {
                if (blockingDeque.size() == 0) {
                    System.out.printf("[consumer] !!! 队列当前尺寸 %d: ，里面啥也没有，暂时拉取消息\n", blockingDeque.size());
                    continue;
                }

                String s = blockingDeque.take();
                System.out.println("[consumer] 当前消费者线程:" + Thread.currentThread().toString());
                System.out.println("[consumer] 消费者收到消息:" + s);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
